package com.ungao.demo.controller;

import com.ungao.demo.service.TestService;
import com.ungao.framework.annotation.Autowired;
import com.ungao.framework.web.annotation.RequestController;
import com.ungao.framework.web.annotation.RequestMapping;
import com.ungao.framework.web.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequestController
@RequestMapping(value = "/test")
public class TestController {

    @Autowired
    private TestService testService;

    @RequestMapping(value = "/hello")
    public void test(HttpServletRequest request, HttpServletResponse response, String name) throws Exception {
        response.getWriter().write(testService.hello(name));
    }

    @RequestMapping(value = "/all")
    public void all(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.getWriter().write(testService.selectList().toString());
    }

    @RequestMapping(value = "/user")
    public void user(HttpServletRequest request, HttpServletResponse response, @RequestParam("id") int id) throws Exception {
        response.getWriter().write(testService.selectOne(id).toString());
    }
}
